package com.bawei.mvvmdemo;

import androidx.appcompat.app.AppCompatActivity;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;

import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;

import com.bawei.mvvmdemo.entity.BannerEntity;
import com.bawei.mvvmdemo.entity.BaseResponseEntity;
import com.bawei.mvvmdemo.entity.GoodsEntity;
import com.bawei.mvvmdemo.entity.TypeEntity;
import com.bawei.mvvmdemo.viewmodel.GoodsViewModel;

import java.util.List;

public class MainActivity extends AppCompatActivity {
    private GoodsViewModel mGoodsViewModel;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mGoodsViewModel = new ViewModelProvider(this).get(GoodsViewModel.class);

        mGoodsViewModel.banner(0,1,10).observe(this, new Observer<BaseResponseEntity<BannerEntity>>() {
            @Override
            public void onChanged(BaseResponseEntity<BannerEntity> bannerEntityBaseResponseEntity) {
                //显示对应的轮播图数据，banner中
                List<BannerEntity.ListBean> list = bannerEntityBaseResponseEntity.getData().getList();
                for (BannerEntity.ListBean listBean : list) {
                    Log.d("ytx", "banner: "+listBean.getTitle());

                }
            }
        });

        mGoodsViewModel.type(0).observe(this, new Observer<BaseResponseEntity<List<TypeEntity>>>() {
            @Override
            public void onChanged(BaseResponseEntity<List<TypeEntity>> listBaseResponseEntity) {
                //显示分类的数据，recyclerview中
                List<TypeEntity> data = listBaseResponseEntity.getData();
                for (TypeEntity datum : data) {
                    Log.d("ytx", datum.getCategoryName());
                }
            }
        });

        mGoodsViewModel.goods(14,1,10).observe(this, new Observer<BaseResponseEntity<GoodsEntity>>() {
            @Override
            public void onChanged(BaseResponseEntity<GoodsEntity> goodsEntityBaseResponseEntity) {
                List<GoodsEntity.ListBean> list = goodsEntityBaseResponseEntity.getData().getList();
                for (GoodsEntity.ListBean listBean : list) {
                    Log.d("ytx", listBean.getGoodsDesc());
                }
            }
        });
    }
}